//
//  WDWorderOrdRevVehDetailServiceInfoView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/31.
//

#import "WDWorderOrdRevVehDetailServiceInfoView.h"
#import "WDArrivalServiceDetailModel.h"

@interface WDWorderOrdRevVehDetailServiceInfoView ()
@property (nonatomic, strong) WDArrivalServiceDetailModel *taskDetailModel;

/// 创建时间
@property (nonatomic, strong) WDTaskDetailBasicSingleView *createTimeView;

/// 预约时间
@property (nonatomic, strong) WDTaskDetailBasicSingleView *appointTimeView;

/// 接车时间
@property (nonatomic, strong) WDTaskDetailBasicSingleView *meetCarTimeView;

/// 扫码位置
@property (nonatomic, strong) WDTaskDetailBasicSingleView *scanLocationView;

/// 扫码账户
@property (nonatomic, strong) WDTaskDetailBasicSingleView *scanAccountView;

/// 预约时间
- (void)initWithAppointTimeView;

/// 接车时间
- (void)initWithMeetCarTimeView;

/// 扫码位置
- (void)initWithScanLocationView;

/// 扫码账户
- (void)initWithScanAccountView;

@end

@implementation WDWorderOrdRevVehDetailServiceInfoView

- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = [UIColor whiteColor];
    
}

/// 创建时间
- (void)initWithCreateTimeView {
    if (!_createTimeView) {
        CGRect frame = CGRectMake(0, 0, self.width, kWDTaskDetailBasicSingleViewHeight);
        _createTimeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_createTimeView];
    }
    if (self.taskDetailModel) {
        NSString *str = objectNull(self.taskDetailModel.createTime);
        if ([str isEqualToString:@""]) {
            str = @"--";
        }
        [_createTimeView updateWithViewTitle:@"创建时间" value:str valueHeight:18];
    }
}

/// 预约时间
- (void)initWithAppointTimeView {
    if (!_appointTimeView) {
        CGRect frame = self.createTimeView.frame;
        frame.origin.y = self.createTimeView.bottom;
        _appointTimeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_appointTimeView];
    }
    if (self.taskDetailModel) {
        NSString *str = objectNull(self.taskDetailModel.appointmentTime);
        if ([str isEqualToString:@""]) {
            str = @"--";
        }
        [_appointTimeView updateWithViewTitle:@"预约时间" value:str valueHeight:18];
    }
}

/// 接车时间
- (void)initWithMeetCarTimeView {
    if (!_meetCarTimeView) {
        CGRect frame = self.appointTimeView.frame;
        frame.origin.y = self.appointTimeView.bottom;
        _meetCarTimeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_meetCarTimeView];
    }
    if (self.taskDetailModel) {
        WDTaskFlowModel *flowModel = self.taskDetailModel.taskFlowList.firstObject;
        if (flowModel) {
            [_meetCarTimeView updateWithViewTitle:@"接车时间" value:flowModel.createTime valueHeight:18];
        } else {
            [_meetCarTimeView updateWithViewTitle:@"接车时间" value:@"" valueHeight:18];
        }
    }
}

/// 扫码位置
- (void)initWithScanLocationView {
    float height = 18;
    WDTaskFlowModel *flowModel = self.taskDetailModel.taskFlowList.firstObject;
    if (flowModel && flowModel.scanAddressHeight > 18) {
        height = flowModel.scanAddressHeight;
    }
    if (!_scanLocationView) {
        CGRect frame = self.appointTimeView.frame;
        frame.origin.y = self.meetCarTimeView.bottom;
        frame.size.height = 10 + height;
        _scanLocationView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_scanLocationView];
    }
    if (self.taskDetailModel) {
//        WDTaskFlowModel *flowModel = self.taskDetailModel.taskFlowList.firstObject;
        if (flowModel) {
            [_scanLocationView updateWithViewTitle:@"扫码位置" value:flowModel.scanAddress valueHeight:height];
        } else {
            [_scanLocationView updateWithViewTitle:@"扫码位置" value:@"" valueHeight:height];
        }
    }
}

/// 扫码账户
- (void)initWithScanAccountView {
    if (!_scanAccountView) {
        CGRect frame = self.appointTimeView.frame;
        frame.origin.y = self.scanLocationView.bottom;
        _scanAccountView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_scanAccountView];
    }
    if (self.taskDetailModel) {
        WDTaskFlowModel *flowModel = self.taskDetailModel.taskFlowList.firstObject;
        if (flowModel) {
            [_scanAccountView updateWithViewTitle:@"扫码账户" value:flowModel.engineerName valueHeight:18];
        } else {
            [_scanAccountView updateWithViewTitle:@"扫码账户" value:@"" valueHeight:18];
        }
    }
}

- (void)updateWithViewData:(id)data {
    self.taskDetailModel = data;
    
    /// 创建时间
    [self initWithCreateTimeView];
    
    /// 预约时间
    [self initWithAppointTimeView];

    /// 接车时间
    [self initWithMeetCarTimeView];

    /// 扫码位置
    [self initWithScanLocationView];

    /// 扫码账户
    [self initWithScanAccountView];
}

@end
